/**
 * @author KujoMiva
 * @name index.js
 * @desc 路由
 * @time 2020年04月06日 12:43:29 星期一
 */
import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

const constantRoutes = [
    {
        path: '/',
        name: 'home',
        component: () => import(/* webpackChunkName: "HomePage" */ '@/views/home/index.vue'),
    },

    {
        path: '/audio',
        name: 'audio',
        component: () => import(/* webpackChunkName: "AudioModule" */ '@/views/audio/index.vue'),
    },
    {
        path: '/detailAudio/:aid',
        name: 'detailAudio',
        component: () => import(/* webpackChunkName: "AudioModule" */ '@/views/detailAudio/index.vue'),
    },

    {
        path: '/detailArticle/:aid',
        name: 'detailArticle',
        component: () => import(/* webpackChunkName: "ArticleModule" */ '@/views/detailArticle/index.vue'),
    },

    // {
    //     path: '/detailVideo/:id',
    //     name: 'detailVideo',
    //     component: () => import(/* webpackChunkName: "lv2" */ '@/views/detailVideo/index.vue'),
    // },

    {
        path: '/space/:uid',
        name: 'space',
        component: () => import(/* webpackChunkName: "SpaceModule" */ '@/views/space/index.vue'),
    },

    {
        path: '/404',
        name: 'notFound',
        component: () => import(/* webpackChunkName: "AppMpdule" */ '@/views/notFound/index.vue'),
    },
    {
        path: '/login',
        name: 'login',
        component: () => import(/* webpackChunkName: "AppMpdule" */ '@/views/login/index.vue'),
    },

    { path: '*', redirect: '/404' },
];

const createRouter = () => new Router({
    mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
});

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
    const newRouter = createRouter();
    router.matcher = newRouter.matcher; // reset router
}

export default router;
